<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="utf-8" lang="utf-8">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>
   排版类 - CodeIgniter 中文手册|用户手册|用户指南|Wiki文档
  </title>
  <link rel="shortcut icon" href="/user_guide/../images/design/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" media="all" href="/user_guide/userguide.css" />
  <link rel="search" href="/user_guide/../CodeIgniterSearch.xml" type="application/opensearchdescription+xml" title="CodeIgniter 搜索" />
  <link rel="canonical" href="/user_guide/libraries/typography.html" />
  <script type="text/javascript" src="/user_guide/nav/nav.js">
  </script>
  <script type="text/javascript" src="/user_guide/nav/prototype.lite.js">
  </script>
  <script type="text/javascript" src="/user_guide/nav/moo.fx.js">
  </script>
  <script type="text/javascript" src="/user_guide/nav/user_guide_menu.js">
  </script>
  <meta name="robots" content="all" />
  <meta name="author" content="ExpressionEngine Dev Team" />
  <meta name="description" content="CodeIgniter 中文手册, CodeIgniter 用户指南, CodeIgniter User Guide, Wiki 文档" />
 </head>
 <body>
  <!-- START NAVIGATION -->
  <div id="nav">
   <div id="nav_inner">
    <script type="text/javascript">
     create_menu('/user_guide/');
    </script>
   </div>
  </div>
  <script type="text/javascript">
   _setNavigation();
  </script>
  <div id="nav2">
   <a name="top">
   </a>
   <a href="javascript:void(0);" onclick="myHeight.toggle();">
    <img src="/user_guide/images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="切换目录" alt="切换目录" />
   </a>
  </div>
  <div id="masthead">
   <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
    <tr>
     <td width="350">
      <h1>
       CodeIgniter 用户指南 版本 2.0.0
      </h1>
     </td>
     
     <td id="breadcrumb_right">
      <a href="/user_guide/toc.html">
       目录页
      </a>
     </td>
    </tr>
   </table>
  </div>
  <!-- END NAVIGATION -->
  <!-- START BREADCRUMB -->
  <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
   <tr>
    <td id="breadcrumb">
     <a href="/" target="_blank">
      CodeIgniter 中国首页
     </a>
     &nbsp;&#8250;&nbsp;
     <a href="/user_guide/toc.html">用户指南目录</a>
     &nbsp;&#8250;&nbsp;排版类
    </td>
    <td id="searchbox">
     <form method="get" action="http://www.google.com/search" target="google_window">
      <input type="hidden" name="client" value="pub-0176846097796333" />
      <input type="hidden" name="forid" value="1" />
      <input type="hidden" name="ie" value="UTF-8" />
      <input type="hidden" name="oe" value="UTF-8" />
      <input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.org.cn/user_guide/" />
      搜索用户指南&nbsp;
      <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />
      &nbsp;
      <input type="submit" class="submit" name="sa" value="Go" />
     </form>
    </td>
   </tr>
  </table>
  <!-- END BREADCRUMB -->
  <div style="clear:both;text-align:right;padding: 6px 40px 0 0;">
   <a href="http://codeigniter.com/user_guide/libraries/typography.html" target="_blank">
    查看原文
   </a>
  </div>
  <!--<br clear="all"  />-->
  <!-- START CONTENT -->
  <div id="content">
   <h1>
    排版类
   </h1>
   <p>
    排版类提供帮助你格式化文本的函数。
   </p>
   <h2>
    初始化排版类
   </h2>
   <p>
    和CI中的其他类一样, 排版类也需要在控制器中这样用
    <dfn>
     $this-&gt;load-&gt;library
    </dfn>
    方法初始化:
   </p>
   <code>
    $this-&gt;load-&gt;library('typography');
   </code>
   <p>
    一旦被加载, 排版类的对象就可以这样使用:
    <dfn>
     $this-&gt;typography
    </dfn>
   </p>
   <h2>
    auto_typography()
   </h2>
   <p>
    格式化文本以便纠正语义和印刷的错误HTML代码。输入一个字符串输出如下的格式化文本：
   </p>
   <ul>
    <li>
     用一对P标签包住段落（看起来像是用两条线把段落分隔开似的）。
    </li>
    <li>
     除了出现 &lt;pre&gt; 标签外，所有的单个线的分割被转换为 &lt;br /&gt;。
    </li>
    <li>
     块级别的元素，如&lt;div&gt;标签，没有被段落包装，但是如果他们包含段落的话就会包含文本。
    </li>
    <li>
     除了出现在标签中的引号外，引号会被转换成正确的实体。
    </li>
    <li>
     撇号“'”被转换为相应的实体。
    </li>
    <li>
     双破折号 (像 -- 或--) 被转换成 em&#8212;破折号.
    </li>
    <li>
     三个连续的点也会被转换为省略号&#8230;
    </li>
    <li>
     句子后连续的多个空格将被转换为&amp;nbsp;以便在网页中显示。
    </li>
   </ul>
   <p>
    例如：
   </p>
   <code>
    $string = $this-&gt;typography-&gt;auto_typography($string);
   </code>
   <h3>
    参数
   </h3>
   <p>
    有一个可选参数：布尔值
    <kbd>
     TRUE
    </kbd>
    或
    <kbd>
     FALSE
    </kbd>
    决定是否对超过两个的换行进行压缩，减少到两行。
   </p>
   <p>
    默认不压缩. 也就是说, 如果这个参数不设置, 它将如下工作:
   </p>
   <code>
    $string = $this-&gt;typography-&gt;auto_typography($string,
    <kbd>
     FALSE
    </kbd>
    );
   </code>
   <p class="important">
    <strong>
     提示:
    </strong>
    排版格式化可以处理密集数据, 特别是你有很多内容需要格式化处理。如果你选择这个函数处理，你可以考虑
    <a href="../general/caching.html">
     缓存
    </a>
    你的网页。
   </p>
   <h2>
    format_characters()
   </h2>
   <p>
    This function is similar to the
    <dfn>
     auto_typography
    </dfn>
    function above, except that it only does character conversion:
   </p>
   <ul>
    <li>
     Quotes are converted to correctly facing curly quote entities, except those that appear within tags.
    </li>
    <li>
     Apostrophes are converted to curly apostrophe entities.
    </li>
    <li>
     Double dashes (either like -- this or like--this) are converted to em&#8212;dashes.
    </li>
    <li>
     Three consecutive periods either preceding or following a word are converted to ellipsis&#8230;
    </li>
    <li>
     Double spaces following sentences are converted to non-breaking spaces to mimic double spacing.
    </li>
   </ul>
   <p>
    Usage example:
   </p>
   <code>
    $string = $this-&gt;typography-&gt;format_characters($string);
   </code>
   <h2>
    nl2br_except_pre()
   </h2>
   <p>
    Converts newlines to &lt;br /&gt; tags unless they appear within &lt;pre&gt; tags.
This function is identical to the native PHP
    <dfn>
     nl2br()
    </dfn>
    function, except that it ignores &lt;pre&gt; tags.
   </p>
   <p>
    Usage example:
   </p>
   <code>
    $string = $this-&gt;typography-&gt;nl2br_except_pre($string);
   </code>
   <h2>
    protect_braced_quotes
   </h2>
   <p>
    When using the Typography library in conjunction with the Template Parser library it can often be desirable to protect single
  and double quotes within curly braces.  To enable this, set the
    <kbd>
     protect_braced_quotes
    </kbd>
    class property to
    <samp>
     TRUE
    </samp>
    .
   </p>
   <p>
    Usage example:
   </p>
   <code>
    $this-&gt;load-&gt;library('typography');
    <br />
    $this-&gt;typography-&gt;protect_braced_quotes = TRUE;
   </code>
   <p>
    &nbsp;
   </p>
   <div id="Contributors">
    翻译贡献者:
Hex, icebird, neversaylate, tonera
   </div>
   <div id="DocDate">
    最后修改: 2011-02-01 02:03:41
   </div>
  </div>
  <!-- END CONTENT -->
  <div id="footer">
   <p>
    上一个主题:&nbsp;&nbsp;
    <a href="/user_guide/libraries/parser.html">
     模板解析器
    </a>
    &nbsp;&nbsp;&middot;&nbsp;&nbsp;
    <a href="#top">
     页首
    </a>
    &nbsp;&middot;&nbsp;&nbsp;
    <a href="/user_guide/toc.html">用户指南目录</a>
    &nbsp;&nbsp;&middot;&nbsp;&nbsp;下一个主题:&nbsp;&nbsp;
    <a href="/user_guide/libraries/unit_testing.html">
     单元测试类
    </a>
   </p>
   <p>
    <a href="http://codeigniter.com">
     CodeIgniter
    </a>
    &nbsp;&middot;&nbsp; 版权所有 &#169; 2006-2011 &nbsp;&middot;&nbsp;
    <a href="http://ellislab.com/">
     Ellislab, Inc.
    </a>
   </p>
   <p>
    中文化:
    <a href="">
     CodeIgniter 中国
    </a>
    &nbsp;&middot;&nbsp; 制作: Hex &nbsp;&middot;&nbsp; 版本: 1.20 &nbsp;&middot;&nbsp; 鸣谢: 子非鱼
   </p>
  </div>
  
  <div style="display:none">
   
   <noscript>
    <a href="http://www.51.la/?3289908" target="_blank">
     <img alt="我要啦免费统计" src="http://img.users.51.la/3289908.asp" style="border:none" />
    </a>
   </noscript>
  </div>
 </body>
</html>